#!/usr/local/bin/perl
package MAN;
use strict; use warnings;

my $t=$ENV{"IMVTERM"};
my $p=$ENV{"IMVPAGER"};

sub whichs
{
    foreach(@_){
	my $c=(split(/ /,$_,2))[0];
	return "$c not found" unless system("which $c > /dev/null")==0;
    }
    return undef;
}

sub show_kb_man
{
    my $d=$_[0];
    my $h="imv: key-bindings";
    $t="xterm -T \"$h\" -e" unless defined $t;
    $p="less -s -P\'$h\'" unless defined $p;
    my $m=whichs($t,$p,"cat");
    return $m if defined $m;
    system("$t sh -c \"cat \"$d/docs/kb-readme.txt\" \"$d/docs/kb-sys.txt\" \"$d/docs/kb-fio.txt\" \"$d/docs/kb-nav.txt\" \"$d/docs/kb-adj.txt\" \"$d/docs/kb-mpl.txt\" \"$d/docs/kb-ent.txt\" \"$d/docs/kb-srt.txt\" \"$d/docs/kb-tnv.txt\" \"$d/docs/kb-pop.txt\" \"$d/docs/kb-ply.txt\" \"$d/docs/kb-shc.txt\" \"$d/docs/kb-nkc.txt\" \"$d/docs/kb-msc.txt\" \"$d/docs/kb-mou.txt\" |$p\"&");
    return undef;
}

sub show_pod_man
{
    $p="less -s -P\'imv manual page\'" unless defined $p;
    my $m=whichs($p,"pod2man","nroff");
    return $m if defined $m;
    system("pod2man $_[0]|nroff -man|$p");
    return undef;
}

1;
